﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Games
{
    public partial class Form1 : Form
    {
        public int y=10;
        public int x = 10;
        Rectangel1[] ell = new Rectangel1[5];
        
        Ellips elllips=new Ellips();
        Rectangle rectengle = new Rectangle();

        public Form1()
        {
            InitializeComponent();
            this.DoubleBuffered = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            this.Invalidate();
        }
        private void Form_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;
            elllips.Ellips2(g);
            rectengle.Rectangle1(g);
            ell[0] = new Rectangel1(30, 30, 100, 25);
            ell[0].Rectangle2(g);
            ell[1] = new Rectangel1(150, 30,100, 25);
            ell[1].Rectangle2(g);
            ell[2] = new Rectangel1(150, 100, 100, 25);
            ell[2].Rectangle2(g);
            ell[3] = new Rectangel1(400,100, 100, 25);
            ell[3].Rectangle2(g);
            ell[4] = new Rectangel1(200, 200, 100, 25);
            ell[4].Rectangle2(g);
        }
        private void Form1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left&&rectengle.rectangleX>=3)
            {
                rectengle.rectangleX -= 3;
            }
            if (e.KeyCode == Keys.Right && rectengle.rectangleX <= 540)
            {
                rectengle.rectangleX += 3;
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            
            elllips.ellips_Y += y;
            elllips.ellips_X += x;
            if (elllips.ellips_Y == 320 && rectengle.rectangleX < elllips.ellips_X && rectengle.rectangleX + 200 > elllips.ellips_X)
            {
                y *= -1;
            }
            if (elllips.ellips_Y >= this.ClientSize.Height)
            {
                timer1.Stop();
                MessageBox.Show("You losed !!!");
          
            }
            if (elllips.ellips_Y  <= 0)
            {
                y *= -1;
            }
            if (elllips.ellips_X + 36 >= this.ClientSize.Width)
            {
               x *= -1;
            }
            if (elllips.ellips_X <= 0)
            {
                x *= -1;
            }
           Invalidate();
        }
    }

    public class Rectangel1
    {
        public int rectangle_x;
        public int rectangle_y;
        public int rectangle_wihgt;
        public int rectangle_hight;
        public Rectangel1(int rectangle_x, int rectangle_y, int rectangle_wihgt, int rectangle_hight)
        {
            this.rectangle_x = rectangle_x;
            this.rectangle_y = rectangle_y;
            this.rectangle_hight = rectangle_hight;
            this.rectangle_wihgt = rectangle_wihgt;
        }
        public void Rectangle2(Graphics g)
        {
            g.FillRectangle(Brushes.Gold, rectangle_x, rectangle_y, rectangle_wihgt, rectangle_hight);
        }
    }


  public class Ellips
    {
        public int ellips_X = 50;
        public int ellips_Y = 50;
        public void Ellips2(Graphics g)
        {
            Pen p = new Pen(Brushes.LightSkyBlue);
            g.DrawEllipse(p, ellips_X, ellips_Y, 40 ,40);
        }
    }
    class Rectangle
    {
        public int rectangleX = 250;
        internal void Rectangle1(Graphics g)
        {
            g.FillRectangle(Brushes.Gold, rectangleX, 360, 200, 25);
        }
    }
}
